package pub.cleangao.mybatis.quick;

import lombok.Data;
import pub.cleangao.mybatis.execution.UpdateExecution;
import pub.cleangao.mybatis.expression.Expressions;

import java.util.List;
import java.util.Map;


/**
 * Usage:
 * <p>Update.table("user").set(new HashMap<>()).where(Expression.lambda().eq("name","clean")).done();</p>
 */
@Data
public class Update implements Quick<Integer> {

    private UpdateExecution execution;

    private Update(UpdateExecution execution) {
        this.execution = execution;
    }

    public static Update table(String tableName) {
        return new Update(UpdateExecution.startUpdate(tableName));
    }

    public Update set(String... plainValues) {
        execution.addValuesPlain(plainValues);
        return this;
    }

    public Update set(Map<String, Object> mapValues) {
        execution.addValuesMap(mapValues);
        return this;
    }

    public Update set(List<String> columns, List<Object> values) {
        execution.addValuesByColumn(columns, values);
        return this;
    }

    public Update where(Expressions expression) {
        execution.setWhereExpressionList(expression.getWhereExpressionList());
        return this;
    }

    @Override
    public Integer done() throws Exception {
        return (Integer) execution.done();
    }


}
